#include<iostream>
using namespace std;
#include<cstdlib>
#include<cmath>

// random real numbers in [a,b]
double UniformRand(double a, double b){
	return (b-a)*rand()/RAND_MAX + a;
}

int main(){

	srand(time(NULL));// this is necessary if you want the seed to be "random"
	// So here is how you implant this into your code:
	// 1. add Ln12 into your code, to initialize the random seed
	// 2. iteratively call UniformRand(a,b), to generate uniform random numbers in [a,b]
	
	// Below is an example: calculate mean and variance of [0,1] uniform random numbers. Theoretically, we know that mean = 0.5, variace = 1/12. 
	double a = 0, b = 1, x;
	int N = 10000; // The larger N is, the closer sigma and variance will approach theoretical results.
	double mean=0, variance=0;
	cout<<"RAND_MAX="<<RAND_MAX<<endl;
	for(int i=0;i<N;i++){
		x = UniformRand(a,b);
		mean += x; variance += x*x;
	}
	mean /= N;
	variance = variance/N - mean*mean;
	cout<<" mean = "<<mean<<", variance = "<<variance<<", 1.0/12="<<1.0/12<<endl;
	return 0;
}
